package com.cqw.sms.service;

import com.alibaba.fastjson.JSON;
import com.cqw.domain.HttpClientResult;
import com.cqw.sms.MD5Util;
import com.cqw.sms.MWSmsUtil;
import com.cqw.sms.MWSmsUtil1;
import com.cqw.sms.model.ResultContent;
import com.cqw.utils.HttpClientUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
@Slf4j
public class SmsService {

    @Autowired
    private MWSmsUtil mwSmsUtil;

    @Autowired
    private MWSmsUtil1 mwSmsUtil1;

    private static String url = "https://yunapi.wemediacn.com/smsapi/v2/SendSMS";

    private static String url1 = "http://www.dh3t.com/json/sms/SubmitWithSign";


    public static void sendSms(String mobile) throws Exception {
        //boolean b = mwSmsUtil.sendMsg(url, "710061481", "7fdf8552466630a5c7038bfc374fbdcd2a6f6eff", mobile, "谢谢参会：");
        //log.info(String.valueOf(b));

        Map<String, String> header = new HashMap<>();
        header.put("Content-Type", "application/json;charset=UTF-8");

        Map<String, String> params = new HashMap<>();
        params.put("appid","71006202");
        params.put("secret", "ed65833a2017e54f432f6447814c0bf1873a9bd3");
        params.put("mobile", mobile);
        params.put("message", "【太平】谢谢参会：");
        HttpClientResult httpClientResult = HttpClientUtils.doPost(url, header,params);
        String content = httpClientResult.getContent();
        System.out.println(content);
        ResultContent resultContent = JSON.parseObject(content, ResultContent.class);
        System.out.println(JSON.toJSONString(resultContent));

    }

    public static void sendSms1(String mobile) throws Exception {
        //boolean b = mwSmsUtil1.sendMsg(url1, "dh610281", "wku4D9Xe", mobile, "【太平】谢谢参会：");
        //log.info(String.valueOf(b));

        Map<String, String> header = new HashMap<>();
        header.put("Content-Type", "application/json;charset=UTF-8");

        Map<String, String> params = new HashMap<>();
        params.put("account","dh61028");
        params.put("password", MD5Util.getSignMin("wku4D9Xe"));
        params.put("phones", mobile);
        params.put("content", "【太平】谢谢参会：");
        HttpClientResult httpClientResult = HttpClientUtils.doPost(url1, header,params);
        System.out.println(httpClientResult);
    }

    public static void main(String[] args) throws Exception {
        sendSms1("18055666231");
    }


}
